﻿@if (false) {<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.min.js" type="text/javascript" />}
@{string list = "list9", pager = "pager9", entity = "Order";}

<style type="text/css">
    #order1 { width: 649px; font-size: 12px; }
    #orderitemtable1 { border-top: solid 1px rgb(170,170,170); border-left: solid 1px rgb(170,170,170); clear: both; }
    #orderitemtable1 th { width: 80px; }
    .orderi1 p{ margin:0; padding:4px}
    #orderitemtable1 th, #orderitemtable1 td { padding:3px; border-bottom: solid 1px rgb(170,170,170); border-right: solid 1px rgb(170,170,170); }
</style>

<table id="@list" class="scroll" cellpadding="0" cellspacing="0">
</table>
<div id="@pager" class="scroll" style="text-align: center;">
</div>
<div id="orderbutton" style="display:none" title="查看采购排产单" >
<div id="order1" >
<img src="/images/maylogo.png" />
<h1 style="text-align:center">江苏美淼环保科技有限公司</h1>
<h1 style="text-align:center">采购排产单</h1>
<div style="width: 340px; float:left" class="orderi1">
    <p><label>合同编号：</label><label id="number1"></label></p>
    <p><label>供货商：</label><label id="supplier1"></label></p>
    <p><label>地址：</label><label id="address1"></label></p>
    <p><label>电话：</label><label id="phone1"></label></p>
    <p><label>传真：</label><label id="fax1"></label></p>
    <p><label>联系人：</label><label id="supplieruser1" ></label></p>
</div>
<div style="width: 340px; margin-left: 360px;" class="orderi1">
    <p><label class="toright">日期：</label><label id="date1" /></p>
    <p><label class="toright">需方：</label><label id="demand1" /></p>
    <p><label class="toright">地址：</label><label id="daddress1" /></p>
    <p><label class="toright">电话：</label><label id="dphone1" /></p>
    <p><label class="toright">传真：</label><label id="dfax1" /></p>
    <p><label class="toright">联系人：</label><label id="demanduser1" /></p>
</div><br />
    <table id="orderitemtable1" cellspacing="0" cellpadding="0" border="0" class="ui-jqgrid-btable">
        <tr>
            <th class="ui-state-default ui-th-column ui-th-ltr" style="width:100px">编号</th>
            <th class="ui-state-default ui-th-column ui-th-ltr" style="width:140px">配件名称</th>
            <th class="ui-state-default ui-th-column ui-th-ltr">型号</th>
            <th class="ui-state-default ui-th-column ui-th-ltr">数量</th>
            <th class="ui-state-default ui-th-column ui-th-ltr">单位</th>
            <th class="ui-state-default ui-th-column ui-th-ltr">单价</th>
            <th class="ui-state-default ui-th-column ui-th-ltr">总价</th>
        </tr>
    </table>
    <div id="others1">
    <p><label>备注：</label><label  id="remark1" /></p>
    <p><label>产品需求：</label><label id="ProductRequirements1" /></p>
    <p><label>包装需求：</label><label id="PackagingRequirements1" /></p>
    <p><label>交货日期：</label><label id="DeliveryDate1" /></p>
    <p><label>收货地址：</label><label id="DeliveryAddress1" /></p>
    <p><label>收货人：</label><label id="Consignee1" /></p>
    <p><label>收货人电话：</label><label id="ConsigneeTelphone1" /></p>
    <p><label>其他事项：</label><label id="Other1" /></p>
    <p>1. 供方须按本通知单规定的时间、数量、质量交货。</p>
    <p>2. 需方中途变更产品品种和规格，给供方造成损失，需方应承担直接实际损失。</p>
    <p>3. 其他未尽事项，均按中华人民共和国经济合同法办理。经济纠纷由常州市人民法院管辖。</p><br />
    <p><label style=" margin-right:200px">编制：</label><label style=" margin-right:200px">审核：</label><label>批准：</label></p><br />
    <p><label style=" margin-right:300px">卖方盖章：</label><label>买方盖章：</label></p>
    </div>

</div>
</div>
<script type="text/javascript">
    jQuery(function () {
        function clear() {
            $("#number1").text("");
            $("#supplier1").text("");
            $("#address1").text("");
            $("#phone1").text("");
            $("#fax1").text("");
            $("#supplieruser1").text("");
            $("#date1").text("");
            $("#demand1").text("");
            $("#daddress1").text("");
            $("#dphone1").text("");
            $("#dfax1").text("");
            $("#demanduser1").text("");
            $("#remark1").text("");
            $("#ProductRequirements1").text("");
            $("#PackagingRequirements1").text("");
            $("#DeliveryDate1").text("");
            $("#DeliveryAddress1").text("");
            $("#Consignee1").text("");
            $("#ConsigneeTelphone1").text("");
            $("#Other1").text("");

            $("#orderitemtable1 td").parent().remove();
        };
        $("#orderbutton").dialog({
            autoOpen: false,
            height: 580,
            width: 750,
            modal: true,
            buttons: {
                "打印": function () {
                    Print($("#order1"), $("#orderbutton"));
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#@list").jqGrid({
            url: "/@entity/index/",
            colNames: ["编号", "日期", "供方", "电话", "传真", "联系人", "总价", "备注"],
            colModel: [
            $.jgridx.strCol("Number"),
            $.jgridx.dateCol("Date"),
            $.extend(true, $.jgridx.strCol("Supplier.Number"), { editable : false }),
            { name: 'Supplier.Contacts.Phone', index: 'Supplier.Contacts.Phone', width: 80, search: false },
            { name: 'Supplier.Contacts.Fax', index: 'Supplier.Contacts.Fax', width: 80, search: false },
            { name: 'SupplierUser.Name', index: 'SupplierUser.Name', width: 80, search: false },
            { name: 'Total', index: 'Total', width: 80, search: false },
            {
                name: "Remark",
                index: "Remark",
                width: 280,
                editable: true,
                edittype: "textarea",
                search: false
            }
            ],

            pager: $('#@pager'),
            sortname: "@(entity)Id",
            sortorder: "desc",
            subGrid: true,
            subGridUrl: '/OrderItem/index',
            subGridModel: [{
                name: ["物料编号", "配件名称", "规格", "数量", "单位", "单价", "总价"],
                width: [80, 80, 80, 80, 80, 80, 80]
            }],

            loadComplete: function (data) {

                if (!data.success)
                    $(this).jqGrid("clearGridData", true);
            }
        });
        $("#@list").jqGrid('navGrid', '#@pager',
        {
        @if(Roles.IsUserInRole("purchasemanagers")){
            @:edit: true,
            @:del: true,
        }else{
            @:edit: false,
            @:del: false,
        }
            
            add: false,
            search: true,
            refresh: true
        },
        {
            url: "/@entity/edit/"
        },
        {
            url: "/@entity/add/"
        },
        {
            url: "/@entity/delete/"
        }, {}, {}).jqGrid('navButtonAdd', "@pager", { caption: "",
            buttonicon: "ui-icon ui-icon-print",
            onClickButton: function () {
                clear();
                var rowid = $("#@list").jqGrid('getGridParam', 'selrow');
                if(rowid == null){
                    Alert("警告", "请选择一条记录！");
                }
                $.getJSON("/Order/getOrder?id=" + rowid, function (data) {
                    if (data.success) {
                        $("#number1").html(data.number);
                        $("#supplier1").html(data.supplier);
                        $("#address1").html(data.address);
                        $("#phone1").html(data.phone);
                        $("#fax1").html(data.fax);
                        $("#supplieruser1").html(data.supplieruser);
                        $("#date1").html(data.date);
                        $("#demand1").html(data.demand);
                        $("#daddress1").html(data.daddress);
                        $("#dphone1").html(data.dphone);
                        $("#dfax1").html(data.dfax);
                        $("#demanduser1").html(data.demanduser);
                        $("#remark1").html(data.remark);
                        $("#ProductRequirements1").html(data.productrequirements);
                        $("#PackagingRequirements1").html(data.packagingrequirements);
                        $("#DeliveryDate1").html(data.deliverydate);
                        $("#DeliveryAddress1").html(data.deliveryaddress);
                        $("#Consignee1").html(data.consignee);
                        $("#ConsigneeTelphone1").html(data.consigneetelphone);
                        $("#Other1").html(data.other);
                        its = [];
                        $.each(data.orderitems, function (index, value) {
                            its2 = [];
                            $.each(value, function (i, val) {
                                if (i == 3 || i == 5 || i == 6) {
                                    its2.push("<td style='text-align: right'>" + val + "</td>");
                                } else {
                                    its2.push("<td>" + val + "</td>");
                                }
                            });
                            its.push("<tr>" + its2.join('') + "</tr>");
                        });
                        its.push("<tr><td>合计</td><td></td><td></td><td></td><td></td><td></td><td style='text-align: right'>" + data.total + "</td></tr>");
                        $(its.join('')).appendTo($("#orderitemtable1"));

                        $("#orderbutton").dialog("open");
                    } else {
                        Alert("警告", data.message)
                    }
                });
                //$("#order1").dialog("open");
            },
            position: "last",
            title: "查看采购排产单"
        });
    });
</script>